using Microsoft.Win32;

namespace System.Utility.Helper
{
	public static class RegistryHelper
	{
		public static void DeleteRegist(RegistryKey root, string subkey, string name)
		{
			RegistryKey registryKey = root.OpenSubKey(subkey, true);
			try
			{
				if (registryKey != null)
				{
					string[] subKeyNames = registryKey.GetSubKeyNames();
					for (int i = 0; i < (int)subKeyNames.Length; i++)
					{
						if (subKeyNames[i] == name)
						{
							registryKey.DeleteSubKeyTree(name);
						}
					}
				}
				else
				{
					return;
				}
			}
			finally
			{
				if (registryKey != null)
				{
					((IDisposable)registryKey).Dispose();
				}
			}
		}

		public static string GetRegistryData(RegistryKey root, string subkey, string name)
		{
			string str;
			RegistryKey registryKey = root.OpenSubKey(subkey, true);
			try
			{
				string str1 = "";
				if (registryKey != null)
				{
					str1 = registryKey.GetValue(name).ToString();
				}
				str = str1;
			}
			finally
			{
				if (registryKey != null)
				{
					((IDisposable)registryKey).Dispose();
				}
			}
			return str;
		}

		public static bool IsRegistryExist(RegistryKey root, string subkey, string name)
		{
			bool flag;
			RegistryKey registryKey = root.OpenSubKey(subkey, true);
			try
			{
				flag = (registryKey == null ? false : registryKey.GetValue(name) != null);
			}
			finally
			{
				if (registryKey != null)
				{
					((IDisposable)registryKey).Dispose();
				}
			}
			return flag;
		}

		public static void SetRegistryData(RegistryKey root, string subkey, string name, string value, RegistryValueKind registryValueKind)
		{
			RegistryKey registryKey = root.CreateSubKey(subkey);
			try
			{
				if (registryKey != null)
				{
					registryKey.SetValue(name, value, registryValueKind);
				}
			}
			finally
			{
				if (registryKey != null)
				{
					((IDisposable)registryKey).Dispose();
				}
			}
		}
	}
}